﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Common;
using System.Data.Common.CommandTrees;

namespace JeanFish.Data.Common
{
    public class DbCommandDefinition : System.Data.Common.DbCommandDefinition
    {
        private System.Data.Common.DbCommandDefinition commandDefinition;
        private DbCommandTree commandTree;
        private Func<System.Data.Common.DbCommand, DbCommandDefinition, System.Data.Common.DbCommand> commandCreator;

        public DbCommandDefinition(System.Data.Common.DbCommandDefinition commandDefinition,DbCommandTree commandTree,
            Func<System.Data.Common.DbCommand,DbCommandDefinition,System.Data.Common.DbCommand> commandCreator)
        {
            this.commandDefinition = commandDefinition;
            this.commandTree = commandTree;
            this.commandCreator = commandCreator;
        }

        public DbCommandTree CommandTree
        {
            get { return this.commandTree; }
        }

        protected System.Data.Common.DbCommandDefinition CommandDefinition
        {
            get { return this.commandDefinition; }
        }

        public override System.Data.Common.DbCommand CreateCommand()
        {
            return this.commandCreator(this.CommandDefinition.CreateCommand(), this);
        }
    }
}
